package databases

import (
	"fmt"
	"peilian-api/app/global/variable"

	"github.com/go-redis/redis"
)

func InitRedis() (*redis.Client, error) {
	db := redis.NewClient(&redis.Options{
		Addr:     fmt.Sprintf("%s:%d", variable.Config.Redis.Host, variable.Config.Redis.Port),
		Password: variable.Config.Redis.Password,
		DB:       variable.Config.Redis.Db,
	})
	_, err := db.Ping().Result()
	if err != nil {
		return nil, err
	}
	return db, nil
}
